package edu.gym4all.view;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

import com.example.gym4all.R;

import edu.gym4all.service.domain.Cardio;
import edu.gym4all.service.domain.Hypertrophy;
import edu.gym4all.service.domain.Training;
import edu.gym4all.service.organizer.ExerciseOrganizerImpl;

public class TrainingActivity extends Activity {

	ExerciseOrganizerImpl exerciseOrganizer = new ExerciseOrganizerImpl();

	@Override
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		this.setContentView(R.layout.training_activity);

		Bundle bundleTraining = this.getIntent().getExtras();
		Training training = (Training) bundleTraining.getParcelable("training");

		Button addExerciseButton = (Button) this
				.findViewById(R.id.addexerciseButton);
		addExerciseButton.setOnClickListener(new OnClickAddExercise(training));

		List<Hypertrophy> hyperList = this.exerciseOrganizer
				.loadHyperExercises(training, this);
		ArrayAdapter<Hypertrophy> hyperExerciseList = new ArrayAdapter<Hypertrophy>(
				this, android.R.layout.simple_list_item_1, hyperList);
		ListView hyperListView = (ListView) this
				.findViewById(R.id.hyperExerciseList);
		hyperListView.setAdapter(hyperExerciseList);

		List<Cardio> cardioList = this.exerciseOrganizer.loadCardioExercises(
				training, this);
		ArrayAdapter<Cardio> cardioExerciseList = new ArrayAdapter<Cardio>(
				this, android.R.layout.simple_list_item_1, cardioList);
		ListView cardioListView = (ListView) this
				.findViewById(R.id.cardiExerciseList);
		cardioListView.setAdapter(cardioExerciseList);
	}

	private class OnClickAddExercise implements OnClickListener {

		Training training;

		public OnClickAddExercise(Training training) {
			this.training = training;
		}

		@Override
		public void onClick(View v) {
			Intent intent = new Intent(TrainingActivity.this,
					TrainingTypeActivity.class);
			intent.putExtra("training", this.training);
			TrainingActivity.this.startActivity(intent);
		}
	}
}